<template>
	<view class="popup-box" :class="{ 'popup-height': type === 'left' || type === 'right' }">
		<view class="popup-content">
			<view class="content-item">
				<view class="label">
					<view class="point-empty tag1"></view>
					<view class="text"><text>日期选择：</text></view>
				</view>
				<view class="content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<view class="row">
						<view class="label">
							<image class="img" src="/static/img/icon/icon_in.png" mode="aspectFill" />
							<text>进：</text>
						</view>
						<uni-datetime-picker v-model="formData.datetime1Temp" returnType="timestamp"
							type="datetimerange" rangeSeparator="至" />
					</view>
					<view class="row">
						<view class="label">
							<image class="img" src="/static/img/icon/icon_out.png" mode="aspectFill" />
							<text>出：</text>
						</view>
						<uni-datetime-picker v-model="formData.datetime2Temp" returnType="timestamp"
							type="datetimerange" rangeSeparator="至" />
					</view>
				</view>
			</view>
			<view class="divider" />
			<view class="content-item">
				<view class="label">
					<view class="point-empty tag2"></view>
					<view class="text"><text>状态选择：</text></view>
				</view>
				<view class="content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<uni-data-checkbox v-model="formData.checkinStateTemp" :localdata="checkinStateData" />
				</view>
			</view>

		</view>
		<view class="foot-content">
			<button class="ml10 mr10 btn1" type="warn" size="mini" @click="doSubmit()"> 确定 </button>
			<button class="ml10 mr10 btn2" type="warn" size="mini" plain="true" @click="doReset()"> 重置 </button>
		</view>
	</view>
</template>

<script>
	import {
		CheckinStateData
	} from "@/static/config.js"
	export default {
		emits: ['doSure'],
		props: {
			type: {
				type: String,
				default: 'top'
			},
			datetime1: {
				type: Array,
				default () {
					return []
				}
			},
			datetime2: {
				type: Array,
				default () {
					return []
				}
			},
			checkinState: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				checkinStateData: CheckinStateData, // 进出状态
				formData: {
					// 避免直接修改props
					datetime1Temp: this.datetime1,
					datetime2Temp: this.datetime2,
					checkinStateTemp: this.checkinState
				},
				formDataDef: {
					datetime1Temp: [],
					datetime2Temp: [],
					checkinStateTemp: ''
				},
			}
		},

		methods: {
			doSubmit() {
				this.$emit('doSure', {
					data: this.formData
				})
			},
			doReset() {
				this.formData = Object.assign({}, this.formDataDef);
			},
		},
		watch: {
			type: {
				handler(item, index) { //监听到数据变化执行方法 
					this.type = item
				},
				deep: true // 深度监听父组件传过来对象变化 
			},
			datetime1: {
				handler(item, index) {
					this.formData.datetime1Temp = item
				},
				deep: true
			},
			datetime2: {
				handler(item, index) {
					this.formData.datetime2Temp = item
				},
				deep: true
			},
			checkinState: {
				handler(item, index) {
					this.formData.checkinStateTemp = item
				},
				deep: true
			}
		}
	}
</script>
<style lang='scss' scoped>
	.popup-box {
		padding-top: 65px;
		// #ifdef H5
		height: calc(100vh - 45px);
		// #endif
		// #ifdef MP-WEIXIN
		height: 100vh;
		// #endif

		display: flex;
		flex-direction: column;

		.popup-content {
			/* height: 100%; */
			flex: 0.9;

			.content-item {
				display: flex;
				flex-direction: column;
				margin: 20rpx;

				.label {
					display: flex;
					align-items: center;

					.tag1 {
						border: 2px solid $uni-color-primary;
					}

					.tag2 {
						border: 2px solid $uni-color-success;
					}

					.text {
						font-size: 30rpx;
						font-weight: bold;
						margin-left: 16rpx;
					}
				}

				.content {
					width: 88%;
					margin-left: 80rpx;

					.row {
						display: flex;
						margin: 10rpx 0;

						.label {
							.img {
								width: 20px;
								height: 20px;
							}
						}
					}
				}
			}

			.divider {
				background: #E0E3DA;
				width: 100%;
				height: 5rpx;
			}

		}

		.foot-content {
			display: flex;
			align-items: center;

			.btn1 {
				flex: 1;
				background-color: $app-platform-color;
			}

			.btn2 {
				flex: 1;
				color: $app-platform-color !important;
				border: 1px solid $app-platform-color !important;
			}
		}
	}
</style>
